<template>
  <div>

    <el-menu default-active="this.$router.path" router class="el-menu-vertical-demo" active-text-color="#000"
      :collapse="isCollapse">
      <h3>{{ isCollapse ? '后台' : '随心购后台管理系统' }}</h3>
      <!-- 1级菜单 -->
      <el-menu-item @click="clickMenu(item)" v-for="item in noChildren" :key="item.name" :index="item.path">
        <i :class="`el-icon-${item.icon}`"></i>
        <span slot="title">{{ item.label }}</span>
      </el-menu-item>
      <!-- 2级菜单 -->
      <el-submenu v-for="item in hasChildren" :key="item.label" :index="item.label">
        <template slot="title">
          <i :class="`el-icon-${item.icon}`"></i>
          <span>{{ item.label }}</span>
        </template>
        <el-menu-item-group v-for="subItem in item.children " :key="subItem.path" style="padding:0;">
          <el-menu-item :index="subItem.path">
            <template slot="title">
              <i :class="`el-icon-${subItem.icon}`"></i>
              <span>{{ subItem.label }}</span>
            </template></el-menu-item>
        </el-menu-item-group>
      </el-submenu>
      <!-- <el-submenu index="2">
        <template slot="title">
          <i class="el-icon-collection-tag"></i>
          <span>权限/授权</span>
        </template>
        <el-menu-item index="/permissonV">权限信息</el-menu-item>
        <el-menu-item index="/permissonC">权限修改</el-menu-item>
      </el-submenu> -->
    </el-menu>
  </div>
</template>

<script>
export default {
  name: 'asideView',
  data() {
    return {
      menuData: [
        {
          path: '/home',
          name: 'homeView',
          label: '主页展示',
          icon: 's-home',
          url: 'home'
        },
        {
          path: '/setting',
          name: 'settingView',
          label: '系统设置',
          icon: 'menu',
          url: 'setting'
        },
        {
          label: '商品/订单',
          icon: 's-home',
          children: [
            {
              path: '/good',
              name: 'goodView',
              label: '商品',
              icon: 'goods',
              url: 'good'
            }, {
              path: '/order',
              name: 'orderView',
              label: '订单',
              icon: 's-goods',
              url: 'home'
            },
          ]
        },
        {
          label: '权限/授权',
          icon: 'collection-tag',
          children: [
            {
              path: '/permissonV',
              name: 'permissonV',
              label: '权限信息',
              icon: 's-data',
              url: 'good'
            }, {
              path: '/permissonC',
              name: 'permissonC',
              label: '权限修改',
              icon: 's-check',
              url: 'home'
            },
          ]
        }]
    }
  },
  methods: {

  },
  computed: {
    isCollapse() {
      return this.$store.state.tab.isCollapse;
    },
    noChildren() {
      return this.menuData.filter(item => !item.children)
    },
    hasChildren() {
      return this.menuData.filter(item => item.children)
    },
    clickMenu(item) {
      if (this.$route.path != item.path && !(this.$route.path === '/home')) {
        this.$router.push(item.path)
      }
    }
  }
}

</script>

<style lang="less" >
.el-menu {
  background-color: #56a9ff;
  border-right: 0;

  .is-opened {
    background-color: #fff;


    .el-menu-item {
      margin-top: 0;
    }

  }
}

.el-submenu__title i,
.el-menu-item i {
  color: #000;
}

div.el-menu-item-group__title {
  padding: 0;
}

h3 {
  color: #fff;
  font-size: 16px;
  padding: 0 20px;
}
</style>